package jp.co.nes.awssupport.business.logic.description;

/**
 * Lightsail用の説明作成です。
 */
public class AmazonLightsailDescriptionImpl extends BaseDescriptionImpl {

    /**
     * デフォルトコンストラクタです。
     */
    public AmazonLightsailDescriptionImpl() {
    }

    /*
     * (非 Javadoc)
     * @see jp.co.nes.awssupport.business.logic.description.BaseDescriptionImpl#buildDescriptionFromUsageType(java.lang.String, java.lang.String, jp.co.nes.awssupport.business.logic.description.BaseDescriptionImpl.UsageTypeTokenizer)
     */
    @Override
    protected String buildDescriptionFromUsageType(String regionCode, String productName,
            UsageTypeTokenizer usageTypeTokenizer) {
        // 「リージョンコード-BundleUsage:サイズ_os」のパターンの実装

        String kindValue = descriptionInfoHelper.get(productName, usageTypeTokenizer.getKind());
        if (kindValue == null) {
            return null;
        }

        String instanceType = usageTypeTokenizer.getInstanceType();
        if (instanceType == null) {
            return null;
        }

        String[] splitValues = instanceType.split("_");
        String sizeValue = splitValues[0];
        String osValue = null;
        if (splitValues.length == 2) {
            osValue = descriptionInfoHelper.get(productName, splitValues[1]);
            if (osValue == null) {
                return null;
            }
        }

        StringBuilder builder = new StringBuilder();
        builder.append(getDescriptionPrefix(regionCode));
        builder.append(sizeValue);
        builder.append(kindValue);
        if (osValue != null) {
            builder.append(osValue);
        }
        return builder.toString();
    }
}
